#!/usr/bin/perl -wc

package RFCMail::PackIt::Type::List;

use strict;
use warnings;

use RFCMail::PackIt::Access;

# Object is a scalar reference, holding the type of items in the list

sub define {
    my ($class, $name, $type) = @_;
    my $self = \$type;
    bless $self, $class;
    register_type RFCMail::PackIt::Access $name, sub {$self->read(@_)}, sub {$self->write(@_)};
    return ($self);
}

sub read {
    my ($self, $access) = @_;
    my @list;
    while (not $access->at_end) {
	push @list, $access->read_type($$self);
    }
    return (\@list);
}

sub write {
    my $self = shift;
    my $access = shift;
    for (@_) {
	for (@$_) {
	    $access->write_type($$self, $_);
	}
    }
}

1;
